<template>
  <el-dialog title="选择父节点" :close-on-click-modal="false" :visible.sync="visible" append-to-body fullscreen center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
      <el-form inline v-show="searchShow" ref="searchForm" :model="dataForm">
        <el-form-item label="科目代码" prop="code">
          <el-input v-model="dataForm.code" placeholder="科目代码"></el-input>
        </el-form-item>
        <el-form-item label="科目名称" prop="name">
          <el-input v-model="dataForm.name" placeholder="科目名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="searchChange">查询</el-button>
          <el-button type="default" icon="el-icon-delete" @click="searchReset">清空</el-button>
        </el-form-item>
      </el-form>
      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading" style="margin-top: 15px;">
          <el-table-column type="index" width="50">
            <template slot-scope="scope">
              <el-radio :label="scope.row.id" style="position: relative;left: 6px;top:-2px;" @change="checkitem(scope.row)">&nbsp;</el-radio>
            </template>
          </el-table-column>
          <el-table-column prop="code" label="编码"></el-table-column>
          <el-table-column prop="name" label="名称"></el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next">
        </el-pagination>
      </div>

  </el-dialog>
</template>

<script>
  import {fetchList, delObj} from '@/api/eims/subject'
  import {mapGetters} from 'vuex'
  import { filterParams } from "@/util/tools"
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          key: ''
        },
        treeData: [],
        dataList: [],
        searchShow:true,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    methods: {
      init(data){
        this.visible = true
        if(data){
          this.timestamp = data
        }
        this.getDataList()
      },
      getDataList () {
        this.dataListLoading = true
        let params1 = filterParams(this.dataForm);
        let params2 = { current: this.pageIndex, size: this.pageSize};
        this.dataListLoading = true
        fetchList(Object.assign(params2, params1)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
        
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      searchChange() {
        this.pageIndex=1;
        this.getDataList()
      },
      // 搜索清空
      searchReset () {
        this.$refs.searchForm.resetFields();
        this.getDataList(this.page)
      },
      handleSearchShow () {
        this.searchShow = !this.searchShow;
      },
      /**
       * 刷新回调
       */
      refreshChange() {
        this.getDataList(this.page)
      },
      // 选择品种
      checkitem(val) {
        if(this.timestamp){
          val.timestamp = this.timestamp
        }
        this.visible = false
        this.$emit('refreshData',val)
      },
    }
  }
</script>
